import { Component, OnInit } from '@angular/core';
import {NavController} from "@ionic/angular";

@Component({
  selector: 'app-b02',
  templateUrl: './b02.page.html',
  styleUrls: ['./b02.page.scss'],
})
export class B02Page implements OnInit {

  showDiv: boolean;
  constructor(public navCtrl: NavController) { this.showDiv = true;this.ionViewDidLoad() }

  ngOnInit() {
  }
  div1 :HTMLDivElement;
  readonly imgs:string[] = [
    'assets/imgs/shark.jpg',
    'assets/imgs/travel.jpg'
  ];
  imgSrc:string;
  id1:number;
  id2:number;
  colspanProperty:number = 2;
  readonly  cssClass:string[] = ['p1','p2'];
  classProp:string;
  ionViewDidLoad(){
    this.div1 = <HTMLDivElement>document.getElementById('div1');
    this.imgSrc = this.imgs[0];
    this.classProp = this.cssClass[0];
  }
  start(){
    //不用window调用就报错辣
    this.id1 = window.setInterval(()=>{
      if(this.imgSrc == this.imgs[0]){
        this.imgSrc = this.imgs[1];
      }else{
        this.imgSrc = this.imgs[0];
      }
    },1000);
    this.id2 = window.setInterval(()=>{
      if(this.classProp == this.cssClass[0]){
        this.classProp = this.cssClass[1];
      }else{
        this.classProp = this.cssClass[0];
      }
    },2000);
  }

  stop(){
    if(this.id1 == undefined)return;
    clearInterval(this.id1);
    clearInterval(this.id2);
  }
  switchDiv(){
    // this.div1.hidden = !this.div1.hidden;
    this.showDiv = !this.showDiv;
  }
}
